import type { User, CodeType, UserInfo, PatientList, Patient } from '@/types/user'
import { request } from '@/utils/request'

//密码登录
export const loginByPassword = (mobile: string, password: string) => {
  return request.post<User>('/login/password', { mobile, password })
}

//发送验证码
export const sendMobileCode = (mobile: string, type: codeType) => {
  return request.get<{ code: string }>('/code', { params: { mobile, type } })
}

//短信登录
export const loginByMobile = (mobile: string, code: string) => {
  return request.post<User>('/login', { mobile, code })
}

export const userInfo = () => {
  return request.get<UserInfo>('/patient/myUser')
}

export const getPatientList = () => {
  return request.get<PatientList>('/patient/mylist')
}

export const addPatient = (patient: Patient) => {
  return request.post('/patient/add', patient)
}

export const editPatient = (patient: Patient) => {
  return request.put('/patient/update', patient)
}

export const delPatient = (id: string) => {
  return request.delete(`patient/del/${id}`)
}

export const getPatientDetail = (id: string | undefined) => {
  return request.get<Patient>(`/patient/info/${id}`)
}
